/*
${' '}* Copyright ${.now?string('yyyy')} The JA-SIG Collaborative. All rights reserved.
${' '}* distributed with this file and available online at
${' '}*/
package ${basePackage}.application.${module};<#lt>

import ${basePackage}.application.${module}.assembler.${className}Assembler;
import ${basePackage}.application.${module}.command.Create${className}Cmd;
import ${basePackage}.application.${module}.command.Update${className}Cmd;
import ${basePackage}.application.${module}.query.Query${className}PageQuery;
import ${basePackage}.application.${module}.query.${className}Dto;
import ${basePackage}.application.${module}.repository.${className}QueryRepository;
import ${basePackage}.domain.${module}.${className};
import ${basePackage}.domain.${module}.repository.${className}Repository;

import com.lap.framework.dto.page.PageResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * ${tableComment}应用服务层
 *
 * <ol>
 *   <li>不做业务规则，只做技术规则（加密/解密是技术实现，业务不关注）
 *   <li>取数，赋值，对象转换在这层执行
 *   <li>命名有规范，动词+领域名字
 *   <li>如查询比较多，建议分开领域QueryAppService,如:分页查询，分页查询返回关联字段
 * </ol>
 */
@RequiredArgsConstructor
@Service
public class ${className}AppService {

  private final ${className}Assembler ${lowerName}Assembler;
  private final ${className}Repository ${lowerName}Repository;
  private final ${className}QueryRepository ${lowerName}QueryRepository;

  public PageResponse<${className}Dto> query${className}sByPage(Query${className}PageQuery query) {
    return ${lowerName}QueryRepository.findByConditionPaged(query);
  }

  public Integer create${className}(Create${className}Cmd cmd) {
    ${className} ${lowerName} = ${lowerName}Assembler.toDomain(cmd);
    return ${lowerName}Repository.save(${lowerName});
  }

  public Integer update${className}(Integer id, Update${className}Cmd cmd) {
  	//TODO 这里校验是否存在
    ${className} ${lowerName} = ${lowerName}Assembler.toDomain(id, cmd);
    return ${lowerName}Repository.save(${lowerName});
  }

  public Integer delete${className}(Integer id) {
  	//TODO 这里校验是否存在
    return ${lowerName}Repository.deleteById(id);
  }
}
